
# 想读写二进制文件，比如图片，声音文件等
def demo_1():
    with open('../temp/tempfile.bin', 'rb') as f:
        data = f.read()
        print(data)
        f.close()

def demo_2():
    with open('../temp/tempfile.bin', 'wb') as f:
        f.write(b'kepler wangshengkai')
        f.close()

def demo_3():
    with open('tempfile.bin', 'rb') as f:
        data = f.read(16)
        text = data.decode('utf-8')
        print(text)

def demo_4():
    with open('tempfile.bin', 'wb') as f:
        text = 'sksksksksksksk'
        f.write(text.encode('utf-8'))

if __name__ == '__main__':
    # demo_1()
    # demo_2()
    # demo_3()
    demo_4()